/**
 * 
 */
package com.novartis.nims.trialsubmitter;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import org.apache.log4j.Logger;

/**
 * @author SNYDEJO1
 *
 */
class TrialSubmitterStage {

	private TrialSubmitter mTrialSubmitter;
	private PropertyChangeSupport mPropertyChangeSupport;
	protected static final Logger mLogger = Logger.getRootLogger();
	
	private int mProgress = 0;
	private String mMessage = "";
	private boolean mDeterminate = true;

	TrialSubmitterStage(TrialSubmitter ts) {
		mTrialSubmitter = ts;
		mPropertyChangeSupport = new PropertyChangeSupport(this);
	}
	
	final void setProgress(int progress) {
        if (! mPropertyChangeSupport.hasListeners("progress")) {
            return;
        }
        int oldValue = mProgress;
        int newValue = mProgress = progress;
        mPropertyChangeSupport.firePropertyChange("progress", oldValue, newValue);
	}
	
	final void setMessage(String message) {
        if (! mPropertyChangeSupport.hasListeners("message")) {
            return;
        }
        String oldValue = mMessage;
        String newValue = mMessage = message;
        mPropertyChangeSupport.firePropertyChange("message", oldValue, newValue);
	}
	
	final void setDeterminate(boolean determinate) {
        if (! mPropertyChangeSupport.hasListeners("determinate")) {
            return;
        }
        boolean oldValue = mDeterminate;
        boolean newValue = mDeterminate = determinate;
        mPropertyChangeSupport.firePropertyChange("determinate", oldValue, newValue);
	}
	
	final void addPropertyChangeLister(PropertyChangeListener listener) {
		mPropertyChangeSupport.addPropertyChangeListener(listener);
	}

	protected final boolean isCancelled() {
		return mTrialSubmitter.isCancelled();
	}
}
